program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement=^element;
  element=record
    value:integer;
    next:pelement;
  end;
var
  n, t, i:integer;
  head:pelement;
procedure Delete4(head:pelement);
var
  current, current1:pelement;
  tmp:integer;
begin
  tmp:=0;
  current:=head;
  current1:=head;
  while (current^.next<>nil) do
  begin
    current:=current^.next;
    tmp:=tmp+1;
  end;
  if (tmp>=3) then
  begin
    for i:=1 to 4 do
      current1:=current1^.next;
    writeln(head^.next^.next^.next.value);
    dispose(head^.next^.next^.next);
    head^.next^.next^.next:=current1;
  end;
end;
procedure AddtoBegin(var head: pelement; num: integer);
var
  tmp:pelement;
begin
  tmp:=head;
  new(head);
  head^.next:=tmp;
  head^.value:=num;
end;
begin
  readln(n);
  head:=nil;
  for i:=1 to n do
  begin
    readln(t);
    Addtobegin(head,t);
  end;
  for i:=1 to n do
  begin
    Delete4(head);
  end;
  readln;
end.
